package com.cn.springcloudshop.service.impl;

import com.cn.springcloudshop.mapper.YmShopOrderMapper;
import com.cn.springcloudshop.model.CountOrderStatusPOJO;
import com.cn.springcloudshop.model.YmShopOrder;
import com.cn.springcloudshop.model.YmShopOrderExample;
import com.cn.springcloudshop.service.inter.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @Author: wuyanzu
 * @Date: 2018/8/1
 */
@Service("OrderService")
@Transactional(rollbackFor = Exception.class)
public class OrderServiceImpl implements OrderService {

    @Autowired
    YmShopOrderMapper ymShopOrderMapper;

    @Override
    public int countByExample(YmShopOrderExample example) {
        Assert.notNull(example, "订单实例不能为空");
        Integer res = ymShopOrderMapper.countByExample(example);
        return res == null ? 0 : res;
    }

    @Override
    public int updateBatchByPK(List<YmShopOrder> orders) {
        Assert.notEmpty(orders, "订单信息不能为空");
        Integer res = ymShopOrderMapper.updateBatchByPK(orders);
        return res == null ? 0 : res;
    }

    @Override
    public int insert(YmShopOrder record) {
        Assert.notNull(record,"订单信息不能为空");
        Integer res = ymShopOrderMapper.insert(record);
        return res == null ? 0 : res;
    }

    @Override
    public int insertSelective(YmShopOrder record) {
        Assert.notNull(record,"订单不能为空");
        Integer res = ymShopOrderMapper.insertSelective(record);
        return res == null ? 0 : res;
    }

    @Override
    public List<YmShopOrder> selectByExample(YmShopOrderExample example) {
        Assert.notNull(example, "订单实例不能为空");
        return ymShopOrderMapper.selectByExample(example);
    }

    @Override
    public YmShopOrder selectByPrimaryKey(Long shopOrderId) {
        Assert.notNull(shopOrderId,"订单id不能为空");
        return ymShopOrderMapper.selectByPrimaryKey(shopOrderId);
    }

    @Override
    public int updateByPrimaryKeySelective(YmShopOrder record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(YmShopOrder record) {
        Assert.notNull(record,"订单不能为空");
        Integer res = ymShopOrderMapper.updateByPrimaryKey(record);
        return res == null ? 0 : res;
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        Assert.notNull(id, "订单ID不能为空");
        Integer res = ymShopOrderMapper.deleteByPrimaryKey(id);
        return res == null ? 0 : res;
    }

    @Override
    public List<CountOrderStatusPOJO> countByStatus(Long userId) {
        return ymShopOrderMapper.countByStatus(userId);
    }
}
